// spu请求列表数据
// 1. 引入异步对象
import request from '@/utils/request'

enum Api {
 // 获取spu列表的API
 getSpuListApi = '/admin/product',
 // 添加SPU的API
 saveSpuInfoApi = '/admin/product/saveSpuInfo',
 // 更新SPU的API
 updateSpuInfoApi = '/admin/product/updateSpuInfo',
 // 删除SPU的API
 deleteSpuInfoApi = '/admin/product/deleteSpu',
 // 获取所有trademark数据
 getTrademarkApi = '/admin/product/baseTrademark/getTrademarkList',
 // 获取所有的属性数据
 getBaseSaleAttrApi = '/admin/product/baseSaleAttrList',
   // 获取图片列表
   getSpuImageListApi = '/admin/product/spuImageList',
   // 获取基础销售属性列表
   getSpuSaleAttrListApi = '/admin/product/spuSaleAttrList'
}

// 发送请求获取SpuList数据
export const reqGetSpuListData = (page:number, limit: number,category3Id:number) => {
  return request.get(`${Api.getSpuListApi}`+ `/${page}/${limit}?category3Id=${category3Id}`)
}

/**
 * 3.5 获取所有的trademark品牌数据
 * @returns 
 */
export const reqGetAllTrademarkList = () => {
  return request.get<any,any>(Api.getTrademarkApi)
}

// 3.6 获取所有的销售属性列表数据
export const reqGetBaseSaleAttrList = () => {
  return request.get<any,any>(Api.getBaseSaleAttrApi)
}

/**
 * 3.2 定义一个添加spu数据的接口函数
 * @param spuInfo 
 * @returns 
 */
 export const reqSaveSpuInfo = (spuInfo:any) => {
  return request.post<any, any>(Api.saveSpuInfoApi, spuInfo)
}


/**
 * 3.4 定义一个删除spu信息的接口函数
 * @returns 
 */
 export const reqDeleteSpuInfo = (spuId: number) => {
  return request.delete(Api.deleteSpuInfoApi + `/${spuId}`)
}


/**
 * 3.3 定义一个更新spu数据的接口函数
 * @param spuInfo 
 * @returns 
 */
 export const reqUpdateSpuInfo = (spuInfo) => {
  return request.post<any, any>(Api.updateSpuInfoApi, spuInfo)
}

// 3.7. 获取图片列表
export function reqGetSpuImageList(spuId:number) {
  return request.get<any,any>(Api.getSpuImageListApi + `/${spuId}`)
}
// 3.8. 获取属性列表
export function reqGetSpuSaleAttrList(spuId:number) {
  return request.get<any,any>(Api.getSpuSaleAttrListApi + `/${spuId}`)
}
